package vip.xiaonuo.home.modular.setting.company.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.home.modular.setting.company.entity.HomeCompany;
import vip.xiaonuo.home.modular.setting.company.param.HomeCompanyAddParam;
import vip.xiaonuo.home.modular.setting.company.param.HomeCompanyEditParam;
import vip.xiaonuo.home.modular.setting.company.param.HomeCompanyIdParam;
import vip.xiaonuo.home.modular.setting.company.param.HomeCompanyPageParam;
import vip.xiaonuo.home.modular.setting.company.service.HomeCompanyService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 公司信息控制器
 *
 * @author Mr.wu
 * @date  2025/02/21 22:06
 */
@Tag(name = "公司信息控制器")
@RestController
@Validated
public class HomeCompanyController {

    @Resource
    private HomeCompanyService homeCompanyService;

    /**
     * 获取公司信息分页
     *
     * @author Mr.wu
     * @date  2025/02/21 22:06
     */
    @Operation(summary = "获取公司信息分页")
    @SaCheckPermission("/home/setting/company/page")
    @GetMapping("/home/setting/company/page")
    public CommonResult<Page<HomeCompany>> page(HomeCompanyPageParam homeCompanyPageParam) {
        return CommonResult.data(homeCompanyService.page(homeCompanyPageParam));
    }

    /**
     * 添加公司信息
     *
     * @author Mr.wu
     * @date  2025/02/21 22:06
     */
    @Operation(summary = "添加公司信息")
    @CommonLog("添加公司信息")
    @SaCheckPermission("/home/setting/company/add")
    @PostMapping("/home/setting/company/add")
    public CommonResult<String> add(@RequestBody @Valid HomeCompanyAddParam homeCompanyAddParam) {
        homeCompanyService.add(homeCompanyAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑公司信息
     *
     * @author Mr.wu
     * @date  2025/02/21 22:06
     */
    @Operation(summary = "编辑公司信息")
    @CommonLog("编辑公司信息")
    @SaCheckPermission("/home/setting/company/edit")
    @PostMapping("/home/setting/company/edit")
    public CommonResult<String> edit(@RequestBody @Valid HomeCompanyEditParam homeCompanyEditParam) {
        homeCompanyService.edit(homeCompanyEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除公司信息
     *
     * @author Mr.wu
     * @date  2025/02/21 22:06
     */
    @Operation(summary = "删除公司信息")
    @CommonLog("删除公司信息")
    @SaCheckPermission("/home/setting/company/delete")
    @PostMapping("/home/setting/company/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<HomeCompanyIdParam> homeCompanyIdParamList) {
        homeCompanyService.delete(homeCompanyIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取公司信息详情
     *
     * @author Mr.wu
     * @date  2025/02/21 22:06
     */
    @Operation(summary = "获取公司信息详情")
    @SaCheckPermission("/home/setting/company/detail")
    @GetMapping("/home/setting/company/detail")
    public CommonResult<HomeCompany> detail(@Valid HomeCompanyIdParam homeCompanyIdParam) {
        return CommonResult.data(homeCompanyService.detail(homeCompanyIdParam));
    }
}
